//
//  TestEssayLineCell.m
//  ProjectDemo
//
//  Created by IOS3 on 2019/1/4.
//  Copyright © 2019 IOS3. All rights reserved.
//

#import "TestEssayLineCell.h"
#import <YYText.h>


@interface TestEssayLineCell ()

@property (nonatomic, strong) YYLabel *contentLabel;

@end

@implementation TestEssayLineCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.contentLabel = YYLabel.new;
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 30;
    [self.contentView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.contentView);
    }];
    
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    UIFont *font1 = [UIFont systemFontOfSize:16];
    UIFont *font2 = [UIFont systemFontOfSize:18];
    
    NSAttributedString *component1 = [[NSAttributedString alloc] initWithString:@"Benney: " attributes:@{NSFontAttributeName : font2, NSForegroundColorAttributeName : UIColor.redColor}];
    
    NSAttributedString *component2 = [[NSAttributedString alloc] initWithString:@"so tell me, Did dan talk his new movies, Did dan talk his new movies" attributes:@{NSFontAttributeName : font1, NSForegroundColorAttributeName : UIColor.blueColor}];
    
    UIImage *image = [UIImage imageWithColor:UIColor.greenColor size:CGSizeMake(50, 20)];
    NSMutableAttributedString *component3 = [NSMutableAttributedString yy_attachmentStringWithContent:image contentMode:UIViewContentModeCenter attachmentSize:image.size alignToFont:font1 alignment:YYTextVerticalAlignmentCenter];
    
    [text appendAttributedString:component1];
    [text appendAttributedString:component3];
    [text appendAttributedString:component2];
    
    self.contentLabel.attributedText = text;
    
    NSLog(@"size: %@", NSStringFromCGSize(text.size));
}

@end
